package com.sfac.javaSpringCloudTest.dao;

import com.sfac.entity.test.Country;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Description CountryDao
 * @Author HymanHu
 * @Date 2021/8/19 15:24
 */
@Mapper
@Repository
public interface CountryDao {

    @Select("select * from test_country where country_id = #{countryId}")
    @Results(id="countryResults", value = {
        @Result(column = "country_id", property = "countryId"),
        @Result(column = "country_id",
                property = "cities",
                javaType = List.class,
                many = @Many(select="com.sfac.javaSpringCloudTest.dao.CityDao.getCitiesByCountryId")
        )
    })
    Country getCountryByCountryId(int countryId);

    @Select("select * from test_country where country_name = #{countryName} " +
            "and local_country_name = #{localCountryName}")
    @ResultMap(value="countryResults")
    Country getCountryByCountryName(@Param("countryName") String countryName,
                                    @Param("localCountryName") String localCountryName);
}
